﻿using FANUC.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;

namespace FANUC.Controllers
{
    public class RobotCurrentMeasurementDataController : ApiController
    {
        private FANUCDB db = new FANUCDB();

        [ResponseType(typeof(UnitMeasurementHistoryOnePart_SeialDtoOutput))]
        public IHttpActionResult Get(int id)
        {
            //string part_serial = db.Part_Unit.Where(a => a.Robot_ID == id).OrderByDescending(a => a.Start_Time).FirstOrDefault().Part_Serial;
            
            //var records = db.Pass_Value_History.Where(a => a.Part_Serial == part_serial).ToList();
            //if (records.Count <= 0)
            //{
            //    return NotFound();
            //}
            ////AutoMapper.Mapper.Initialize(cfg => cfg.CreateMap<Pass_Value_History, Pass_Value_HistoryDto>());
            ////List<Pass_Value_HistoryDto> recordsDto = AutoMapper.Mapper.Map<List<Pass_Value_HistoryDto>>(records);
            ////UnitMeasurementHistoryDtoOutput data = new UnitMeasurementHistoryDtoOutput();
            ////data.Pass_Value_History = recordsDto;

            //List<Pass_Value_HistoryDto> recordsDto = new List<Pass_Value_HistoryDto>();
            //foreach (var record in records)
            //{
            //    Pass_Value_HistoryDto dto = new Pass_Value_HistoryDto();
            //    dto.End_Time = record.End_Time;
            //    dto.Insert_Time = record.Insert_Time;
            //    dto.Para_Value1 = record.Para_Value1;
            //    dto.Para_Value2 = record.Para_Value2;
            //    dto.Para_Value3 = record.Para_Value3;
            //    dto.Part_Serial = record.Part_Serial;
            //    dto.Pass_No = record.Pass_No;
            //    dto.Start_Time = record.Start_Time;
            //    dto.Weave_Value1 = record.Weave_Value1;
            //    dto.Weave_Value2 = record.Weave_Value2;
            //    dto.Weave_Value3 = record.Weave_Value3;
            //    dto.Weave_Value4 = record.Weave_Value4;
            //    string[] dataCurrent = record.Data_Current.Split(',');
            //    List<decimal> dataCurrentDecimal = new List<decimal>();
            //    foreach (string s in dataCurrent)
            //    {
            //        if (string.IsNullOrWhiteSpace(s) || string.IsNullOrWhiteSpace(s) || s == "")
            //        {
            //            dataCurrentDecimal.Add(0);
            //        }
            //        else
            //        {
            //            dataCurrentDecimal.Add(decimal.Parse(s));
            //        }
                   
            //    }
            //    dto.Data_Current = dataCurrentDecimal;

            //    string[] dataVoltage = record.Data_Voltage.Split(',');
            //    List<decimal> dataVoltageDecimal = new List<decimal>();
            //    foreach (string s in dataVoltage)
            //    {
            //        if (string.IsNullOrWhiteSpace(s) || string.IsNullOrWhiteSpace(s) || s == "")
            //        {
            //            dataVoltageDecimal.Add(0);
            //        }
            //        else
            //        {
            //            dataVoltageDecimal.Add(decimal.Parse(s));
            //        }
            //    }
            //    dto.Data_Voltage = dataVoltageDecimal;

            //    recordsDto.Add(dto);
            //}
            //UnitMeasurementHistoryDtoOutput data = new UnitMeasurementHistoryDtoOutput();
            //data.Part_Serial = part_serial;
            //data.Pass_Value_History = recordsDto;
            return Ok();
        }
    }
}
